home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / ODUtils / Unused / InfoUtil.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-16  |  42.8 KB  |  1,673 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        InfoUtil.cpp
  3.  
  4.     Contains:    implementation of Info getters & setters
  5.  
  6.     Owned by:    Tantek Çelik
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     
  11.     In Progress:
  12.         
  13. */
  14.  
  15. #ifndef _PLFMDEF_
  16. #include "PlfmDef.h"
  17. #endif
  18.  
  19. #ifndef _STDTYPIO_
  20. #include "StdTypIO.h"
  21. #endif
  22.  
  23. #ifndef _USERSRCM_
  24. #include "UseRsrcM.h"
  25. #endif
  26.  
  27. #ifndef SOM_ODSession_xh
  28. #include <ODSessn.xh>
  29. #endif
  30.  
  31. #ifndef SOM_ODDraft_xh
  32. #include <Draft.xh>
  33. #endif
  34.  
  35. #ifndef SOM_ODDocument_xh
  36. #include <Document.xh>
  37. #endif
  38.  
  39. #ifndef SOM_ODContainer_xh
  40. #include <ODCtr.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODWindowState_xh
  44. #include <WinStat.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODWindow_xh
  48. #include <Window.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODStorageUnit_xh
  52. #include <StorageU.xh>
  53. #endif
  54.  
  55. #ifndef SOM_Module_OpenDoc_StdProps_defined
  56. #include <StdProps.xh>
  57. #endif
  58.  
  59. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  60. #include <StdTypes.xh>
  61. #endif
  62.  
  63. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  64. #include <StdDefs.xh>
  65. #endif
  66.  
  67. #ifndef _ODUTILS_
  68. #include <ODUtils.h>
  69. #endif
  70.  
  71. #ifndef _DLOGUTIL_
  72. #include <DlogUtil.h>
  73. #endif
  74.  
  75. #ifndef SOM_ODFrame_xh
  76. #include <Frame.xh>
  77. #endif
  78.  
  79. #ifndef SOM_ODFacet_xh
  80. #include <Facet.xh>
  81. #endif
  82.  
  83. #ifndef SOM_ODPart_xh
  84. #include <Part.xh>
  85. #endif
  86.  
  87. #ifndef SOM_ODBinding_xh
  88. #include <ODBindng.xh>
  89. #endif
  90.  
  91. #ifndef SOM_ODStorageUnitView_xh
  92. #include <SUView.xh>
  93. #endif
  94.  
  95. #ifndef _PASCLSTR_
  96. #include "PasclStr.h"
  97. #endif
  98.  
  99. #ifndef _ODMEMORY_
  100. #include "ODMemory.h"
  101. #endif
  102.  
  103. #ifndef _PLFMFILE_
  104. #include <PlfmFile.h>
  105. #endif
  106.  
  107. #ifndef _ITEXT_
  108. #include <IText.h>
  109. #endif
  110.  
  111. #ifndef SOM_ODTypeList_xh
  112. #include <TypeList.xh>
  113. #endif
  114.  
  115. #ifndef SOM_ODTypeListIterator_xh
  116. #include <TypLsItr.xh>
  117. #endif
  118.  
  119. #ifndef _EXCEPT_
  120. #include "Except.h"
  121. #endif
  122.  
  123. #ifndef _BNDNSUTL_
  124. #include "BndNSUtl.h"
  125. #endif
  126.  
  127. #ifdef __SC__
  128. #ifndef __PACKAGES__
  129. #include <Packages.h>
  130. #endif
  131. #else
  132. #ifndef __TEXTUTILS__
  133. #include <TextUtils.h>
  134. #endif
  135. #endif
  136.  
  137. #ifndef __STRING__
  138. #include <String.h>
  139. #endif
  140.  
  141. #ifndef __GESTALTEQU__
  142. #include <GestaltEqu.h>
  143. #endif
  144.  
  145. #ifndef __DIALOGS__
  146. #include <Dialogs.h>
  147. #endif
  148.  
  149. #ifndef __TOOLUTILS__
  150. #include <ToolUtils.h>
  151. #endif
  152.  
  153. #ifndef __FONTS__
  154. #include <Fonts.h>
  155. #endif
  156.  
  157. #ifndef __CONTROLS__
  158. #include <Controls.h>
  159. #endif
  160.  
  161. #ifndef __ICONS__
  162. #include <Icons.h>
  163. #endif
  164.  
  165. #ifndef __FINDER__
  166. #include <Finder.h>
  167. #endif
  168.  
  169. #ifndef _INFOUTIL_
  170. #include "InfoUtil.h"
  171. #endif
  172.  
  173. #ifndef SOM_ODTranslation_xh
  174. #include <Translt.xh>
  175. #endif
  176.  
  177. #ifndef _EDITRSET_
  178. #include "EditrSet.h"
  179. #endif
  180.  
  181. #ifndef _STORUTIL_
  182. #include <StorUtil.h>
  183. #endif
  184.  
  185. #ifndef _ISOSTR_
  186. #include "ISOStr.h"
  187. #endif
  188.  
  189. #ifndef SOM_ODWindowIterator_xh
  190. #include <WinIter.xh>
  191. #endif
  192.  
  193. #ifndef SOM_ODNameSpaceManager_xh
  194. #include <NmSpcMg.xh>
  195. #endif
  196.  
  197. #ifndef SOM_ODValueNameSpace_xh
  198. #include <ValueNS.xh>
  199. #endif
  200.  
  201. #ifndef _NMSPCUTL_
  202. #include <NmSpcUtl.h>
  203. #endif
  204.  
  205. #ifndef _UTILDEFS_
  206. #include "UtilDefs.h"
  207. #endif
  208.  
  209. #ifndef _TEMPOBJ_
  210. #include <TempObj.h>
  211. #endif
  212.  
  213. #ifndef _ORDCOLL_
  214. #include "OrdColl.h"
  215. #endif
  216.  
  217. #pragma segment Info
  218.  
  219. //==============================================================================
  220. // Constants
  221. //==============================================================================
  222.  
  223. const short kControlInactive = 255;
  224. const short kControlActive = 0;
  225. static const char* const         kODIconFamilyBaseString = kODIconFamily ":";
  226. static const ResType            kIconType[6] = {'ICN#','icl4','icl8','ics#','ics4','ics8'};
  227. static const short                kIconSize[6] = {256,   512,   1024,  64,    128,   256   };
  228.  
  229. const ODPlatformType kODFileType_hfs = 0x68667320;    // 'hfs '
  230.  
  231. //==============================================================================
  232. // Static Function declarations
  233. //==============================================================================
  234.  
  235. ODTime    ODGetDateProperty(Environment* ev, 
  236.             ODStorageUnit* su,
  237.             ODPropertyName prop);
  238.  
  239. void    ODSetDateProperty(Environment* ev, 
  240.             ODStorageUnit* su,
  241.             ODPropertyName prop,
  242.             ODTime dateTime);
  243.  
  244. ODStatic ODBoolean         ODUserRenameFile(Environment* ev,
  245.                                 ODSession* session,
  246.                                 PlatformFile*    usersFile, 
  247.                                 ODIText* name,
  248.                                 DescType replaceOption);
  249. // If PlatformFile is made a shared utility, then the above function should probably be
  250. // integrated into the PlatformFile::Rename method.
  251.  
  252. ODStatic ODIconFamily    GetGenericIcon( short iconID );
  253.  
  254. ODStatic OSErr             DetachIconProc( ResType, Handle *theIcon, void */*yourDataPtr*/ );
  255.  
  256. ODStatic ODBoolean        CommentsDontMatch(ODIText* dtComments, ODIText* propComments);
  257.  
  258. //==============================================================================
  259. // Info functions
  260. //==============================================================================
  261.  
  262.  
  263. ODStorageUnit* ODGetSUFromPstObj(Environment* ev, ODPersistentObject* pstobj)
  264. {
  265.     return pstobj->GetStorageUnit(ev);
  266. }
  267.  
  268. //-------------------------------------------------------------------------------------
  269. // Part & Frame Property getters and setters
  270. //-------------------------------------------------------------------------------------
  271.  
  272. ODIText*
  273. ODGetPOComments(Environment* ev, ODPart *part, ODIText* comments)
  274. {
  275.     ODStorageUnit*    su = ODGetSUFromPstObj(ev, part);
  276.     ODIText*        propComments;
  277.  
  278.     propComments = ODGetITextProp(ev, su, kODPropComments, kODMacIText, comments);
  279.     return propComments;
  280. }
  281.  
  282. void    ODSetPOComments(Environment* ev, ODPart *part, ODIText* comments)
  283. {
  284.     ODStorageUnit*    su = ODGetSUFromPstObj(ev, part);
  285.     
  286.     ODSetITextProp(ev, su, kODPropComments, kODMacIText, comments);
  287. }
  288.  
  289.  
  290. ODIText*
  291. ODGetComments(Environment* ev, ODFrame* frame, ODIText* comments)
  292. {
  293.     TempODPart        part = frame->AcquirePart(ev);
  294.     ODIText*        propComments;
  295.     ODIText*        dtComments;
  296.  
  297.     propComments = ODGetPOComments(ev, part, comments);
  298.     if (comments && !propComments)
  299.         propComments = comments;
  300.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  301.     if (usersFile)
  302.     {
  303.         dtComments = usersFile->GetComments();
  304.         if (dtComments && GetITextStringLength(dtComments) == 0)
  305.         {
  306.             // since there are no desktop comments
  307.             // make the desktop comments match the property
  308.             usersFile->SetComments(propComments);
  309.         }
  310.         else if (CommentsDontMatch(dtComments, propComments) && dtComments)
  311.         {
  312.             // if there are desktop comments and the property comments don't match
  313.             // then the desktop comments take precedence, so return the desktop comments
  314.             DisposeIText(propComments);
  315.             propComments = dtComments;
  316.             dtComments = kODNULL;
  317.         }
  318.         DisposeIText(dtComments);
  319.     }
  320.     return propComments;
  321. }
  322.  
  323. void    ODSetComments(Environment* ev, ODFrame* frame, ODIText* comments)
  324. {
  325.     TempODPart        part = frame->AcquirePart(ev);
  326.     ODSetPOComments(ev, part, comments);
  327.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  328.     if (usersFile)
  329.         usersFile->SetComments(comments);
  330. }
  331.  
  332.  
  333. ODULong    ODGetPOSize(Environment* ev, ODPersistentObject* pstobj)
  334. {
  335.     ODStorageUnit* su = ODGetSUFromPstObj(ev, pstobj);
  336.     su->Focus(ev, kODNULL, kODPosAll, kODNULL,0, kODPosAll);
  337.     return su->GetSize(ev);
  338. }
  339.  
  340. ODID ODGetPOID(Environment* ev, ODPersistentObject* pstobj)
  341. {
  342.     ODStorageUnit* su = ODGetSUFromPstObj(ev, pstobj);
  343.     su->Focus(ev, kODNULL, kODPosAll, kODNULL,0, kODPosAll);
  344.     return su->GetID(ev);
  345. }
  346.  
  347. ODTime    ODGetDateProperty(Environment* ev, 
  348.             ODStorageUnit* su,
  349.             ODPropertyName prop)
  350. {    return ODGetTime_TProp(ev, su, prop, kODTime_T);}
  351.  
  352. void    ODSetDateProperty(Environment* ev, 
  353.             ODStorageUnit* su,
  354.             ODPropertyName prop,
  355.             ODTime dateTime)
  356. {    ODSetTime_TProp(ev, su, prop, kODTime_T, dateTime);}
  357.  
  358.  
  359. ODULong    ODGetCreationDate(Environment* ev, 
  360.                 ODStorageUnit* su)
  361. {    return ODGetDateProperty(ev, su, kODPropCreateDate);}
  362.  
  363. void    ODSetCreationDate(Environment* ev, 
  364.                 ODStorageUnit* su,
  365.                 ODTime dateTime)
  366. {    ODSetDateProperty(ev, su, kODPropCreateDate, dateTime);}
  367.  
  368.  
  369. ODULong    ODGetModificationDate(Environment* ev, 
  370.                 ODStorageUnit* su)
  371. {    return ODGetDateProperty(ev, su, kODPropModDate);}
  372.  
  373. void    ODSetModificationDate(Environment* ev, 
  374.                 ODStorageUnit* su,
  375.                 ODTime dateTime)
  376. {    ODSetDateProperty(ev, su, kODPropModDate, dateTime);}
  377.  
  378.  
  379. ODIText*    ODGetModifiedBy(Environment* ev, 
  380.                 ODStorageUnit* su, ODIText* userName)
  381. {
  382.     return ODGetITextProp(ev, su, kODPropModUser,
  383.             kODMacIText, userName);
  384. }
  385.  
  386. void        ODSetModifiedBy(Environment* ev, 
  387.                 ODStorageUnit* su, ODIText* userName)
  388. {
  389.     ODSetITextProp(ev, su, kODPropModUser,
  390.             kODMacIText, userName);
  391. }
  392.  
  393.  
  394. //-------------------------------------------------------------------------------------
  395. // Part only Property getters and setters
  396. //-------------------------------------------------------------------------------------
  397. ODIText*    ODGetPartName(Environment* ev, 
  398.                 ODFrame* frame, ODIText* name)
  399. {
  400.     TempODPart part = frame->AcquirePart(ev);
  401.     TempODIText partName = ODGetPOName(ev, part, name);
  402.     
  403.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  404.     if (usersFile)
  405.     {
  406.         TempODIText fileName = usersFile->GetName();
  407.         if ( CommentsDontMatch( fileName, partName ) )
  408.             return CopyIText( fileName );
  409.     }
  410.     return CopyIText( partName );
  411. }
  412.  
  413. ODBoolean    ODSetPartName(Environment* ev, 
  414.                 ODFrame* frame, ODIText* name, DescType replaceOption)
  415.         // Renames the part of the frame passed in.
  416.         // Returns whether or not it succeeded.
  417.         // The frame helps more easily determine whether
  418.         // the part is the root part of the document or not.
  419.         // For example, renaming the root part of the document could fail
  420.         // if there was a file with the same name and the user canceled the
  421.         // "Replace?" dialog.
  422. {
  423.     ASSERT(frame != kODNULL, kODErrIllegalNullInput);
  424.     
  425.     TempODPart part = frame->AcquirePart(ev);
  426.     TempODWindow window = frame->AcquireWindow(ev);
  427.                 
  428.     ODFrame*     contFrame = frame->AcquireContainingFrame(ev);
  429.     ODBoolean     isRootPart = (contFrame == kODNULL);
  430.     ODReleaseObject(ev, contFrame);
  431.     
  432.     ODBoolean    isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
  433.     ODBoolean    succeeded = kODTrue;
  434.     
  435.     TRY
  436.         ODName*         oldName = ODGetPartName(ev, frame, kODNULL); 
  437.         ODStorageUnit*    partSU    = ODGetSUFromPstObj(ev, part);
  438.         ODSession*        session = partSU->GetSession(ev);
  439.  
  440.         if (isRootPartOfDocument)
  441.         {
  442.             ODDraft*        draft = partSU->GetDraft(ev);
  443.             PlatformFile*    usersFile = 
  444.                 GetPlatformFileFromContainer(ev, draft->GetDocument(ev)->GetContainer(ev));
  445.  
  446.             if (ODUserRenameFile(ev, session, usersFile, name, replaceOption))
  447.             {
  448.                 ODWindowState* windowState = session->GetWindowState(ev);
  449.                 windowState->SetDefaultWindowTitles(ev, draft);
  450.                 ODSetPOName(ev, part, name);
  451.                 ODRenamePartWindows(ev,session,part,oldName,name);
  452.                 if (isRootPart)
  453.                 {
  454.                     Str255 pName;
  455.                     GetITextPString(name, pName);
  456.                     SetWTitle(window->GetPlatformWindow(ev), pName);
  457.                 }
  458.             }
  459.             else
  460.                 succeeded = kODFalse;
  461.             ODDeleteObject(usersFile);
  462.         }
  463.         else
  464.         {
  465.             ODSetPOName(ev, part,name);
  466.             ODRenamePartWindows(ev,session,part,oldName,name);
  467.         }
  468.         
  469.         DisposeIText(oldName);
  470.  
  471.     CATCH_ALL
  472.         WARN("ODSetPartName failed, error %ld",ErrorCode());
  473.         succeeded = kODFalse;
  474.     ENDTRY
  475.     
  476.     return succeeded;
  477. }
  478.  
  479. void
  480. ODRenamePartWindows( Environment *ev, ODSession *session,
  481.                      ODPart *part, ODIText *oldName, ODIText *name )
  482. {
  483.     // go through all windows which have this part as their root, and
  484.     // have the current name of the part as a prefix
  485.     // rename their prefix to be the new name
  486.     Str255    pOldName;
  487.     Str255    pNewName;
  488.     Str255    pWinTitle;
  489.     ODUByte pOldNameLen;
  490.     ODUByte pNewNameLen;
  491.     
  492.     GetITextPString(oldName, pOldName);
  493.     pOldNameLen = pOldName[0];
  494.     GetITextPString(name, pNewName);
  495.     pNewNameLen = pNewName[0];
  496.     
  497.     ODWindowIterator* iter = session->GetWindowState(ev)->CreateWindowIterator(ev);
  498.     for (ODWindow* window = iter->First(ev); 
  499.          iter->IsNotComplete(ev);
  500.          window = iter->Next(ev))
  501.     {
  502.         TempODPart winPart = window->GetRootFrame(ev)->AcquirePart(ev);
  503.         if (ODObjectsAreEqual(ev, part, winPart))
  504.         {
  505.             // Check to see if name of window has pOldName as prefix
  506.             ODPlatformWindow pwindow = window->GetPlatformWindow(ev);
  507.             GetWTitle(pwindow, pWinTitle);
  508.             if (!strncmp((char*)&pWinTitle[1], (char*)&pOldName[1], pOldNameLen) &&
  509.                     !EqualPascalStrings(pWinTitle, pNewName))
  510.             {
  511.                 ODUByte suffixLen = pWinTitle[0] - pOldNameLen;
  512.                 if (suffixLen + pNewNameLen > 255) 
  513.                     suffixLen = 255 - pNewNameLen;
  514.                 strncpy((char*)&pNewName[pNewNameLen+1], 
  515.                         (char*)&pWinTitle[pOldNameLen+1],
  516.                         suffixLen);
  517.                 pNewName[0] = pNewNameLen+suffixLen;
  518.                 SetWTitle(pwindow, pNewName);
  519.             }
  520.         }
  521.     }
  522.     ODDeleteObject(iter);
  523. }
  524.  
  525.  
  526. ODIText*    ODGetPOName(Environment* ev, ODPersistentObject* pstobj,ODIText* name)
  527. {
  528.     return ODGetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, kODMacIText,name);
  529. }
  530.  
  531. void        ODSetPOName(Environment* ev, ODPersistentObject* pstobj,ODIText* name)
  532. {
  533.     ODSetITextProp(ev, ODGetSUFromPstObj(ev, pstobj), kODPropName, kODMacIText, name);
  534. }
  535.  
  536. void        ODSetPONameUsingSU(Environment* ev, ODStorageUnit* su, ODIText* name)
  537. {
  538.     ODSetITextProp(ev, su, kODPropName, kODMacIText, name);
  539. }
  540.  
  541. ODName*    ODGetCategory(Environment* ev, ODPart* part, ODNameSpaceManager* nsm)
  542. {
  543.     return ODGetCatFromPartSU(ev, ODGetSUFromPstObj(ev, part), nsm);
  544. }
  545.  
  546. ODName*    ODGetCatFromPartSU(Environment* ev, ODStorageUnit* su, ODNameSpaceManager* nsm)
  547. {
  548.     ODType kind = ODGetKindFromPartSU(ev, su);
  549.     ODName*    categoryName = ODGetCatFromKind(ev, kind, nsm);
  550.     ODDisposePtr( kind );
  551.  
  552.     return categoryName;
  553. }
  554.  
  555. ODName*    ODGetCatFromKind(Environment* ev, ODType kind, ODNameSpaceManager* nsm)
  556. {
  557.     StringHandle strHandle = 0;
  558.     ODTypeList* categoryList = GetCategoriesOfKind(nsm, kind);
  559.     ODTypeListIterator* catIter = kODNULL;
  560.     ODType category = kODNULL;
  561.     ODName*    categoryName = kODNULL;
  562.     
  563.     if (categoryList)
  564.     {
  565.         catIter = categoryList->CreateTypeListIterator(ev);
  566.         category = catIter->First(ev);
  567.         ODDeleteObject(catIter);
  568.     }
  569.     
  570.     if (category == kODNULL || !GetUserCatFromCat(nsm, category, &categoryName)) {
  571.         CUsingLibraryResources r;
  572.         categoryName = GetODIText(kODPartInfoStrUnknownID);
  573.     }
  574.     //else // make a disposable copy // NO NEED TO! GetUserCatFromCat returns a copy!
  575.     //    categoryName = CopyIText(categoryName);
  576.         
  577.     ODDisposePtr(category);
  578.  
  579.     return categoryName;
  580. }
  581.  
  582. ODType    ODGetKindFromPartSU(Environment* ev, ODStorageUnit* su)
  583. {
  584.     ODULong unused;
  585.     ODType kind = ODGetISOStrProp(ev, su, kODPropPreferredKind, kODISOStr, kODNULL, &unused);
  586.     if ( kind == kODNULL )
  587.         if ( su->Exists(ev, kODPropContents, (ODValueType) kODNULL,1) )
  588.         {
  589.             su->Focus(ev, kODPropContents, kODPosSame, (ODValueType) kODNULL,1, kODPosSame);
  590.             kind = su->GetType(ev);
  591.  
  592.             ODTranslation* translation = su->GetSession(ev)->GetTranslation(ev);
  593.             TempODType hfsType = 
  594.                 translation->GetISOTypeFromPlatformType(ev, kODFileType_hfs, kODPlatformDataType);
  595.  
  596.             if ( ODISOStrEqual(kind, hfsType) )
  597.             {
  598.                 ODDisposePtr(kind);
  599.                 kind = kODNULL;
  600.                 if ( su->Exists(ev, kODPropContents, (ODValueType) kODNULL,2) )
  601.                 {
  602.                     su->Focus(ev, kODPropContents, kODPosSame, (ODValueType) kODNULL,2, kODPosSame);
  603.                     kind = su->GetType(ev);
  604.                 }
  605.             }
  606.         }
  607.     return kind;
  608. }
  609.  
  610. ODType    ODGetKind(Environment* ev, ODPart* part)
  611. {
  612.     return ODGetKindFromPartSU(ev, ODGetSUFromPstObj(ev, part));
  613. }
  614.  
  615. ODPlatformType ODGetIconFilePlatformTypeFromPartSU(Environment* ev, ODStorageUnit* su)
  616. {
  617.     ODSession* session = su->GetSession(ev);
  618.     
  619.     ODType partKind = ODGetKindFromPartSU(ev, su);
  620.     ODPlatformType partOSType = session->GetTranslation(ev)->
  621.                             GetPlatformTypeFromISOType(ev, partKind);
  622.     if (partOSType != kODNULL)
  623.     {
  624.         ((ODUByte*)(&partOSType))[0] = kODPlatformKindFileChar1;
  625.     }
  626.     else
  627.     {
  628.         ODBoolean    partOSTypeFound = kODFalse;
  629.         ODValueNameSpace*    osTypeNameSpace = (ODValueNameSpace*)
  630.             (session->GetNameSpaceManager(ev)->HasNameSpace(ev, kODKindOldMacOSType));
  631.     
  632.         if (osTypeNameSpace)
  633.         {
  634.             ODPlatformType* typePtr;
  635.             ODULong        unusedLength;
  636.             partOSTypeFound = ValueNameSpaceGetEntry(osTypeNameSpace, 
  637.                                                         ev, partKind, 
  638.                                                         (ODPtr*) &typePtr, 
  639.                                                         &unusedLength);
  640.             if (partOSTypeFound)
  641.             {
  642.                 partOSType = *typePtr;
  643.                 ODDeleteObject( typePtr );
  644.             }
  645.         }
  646.         if (!partOSTypeFound)
  647.             partOSType = kODShellSignature;
  648.     }
  649.     
  650.     ODDisposePtr(partKind);
  651.  
  652.     return partOSType;
  653. }
  654.  
  655.  
  656. //--------------------------------------------------------------------
  657. // ODGetPOIconFamily
  658. //--------------------------------------------------------------------
  659.  
  660. ODIconFamily
  661. ODGetPOIconFamily(Environment* ev, ODPart* part)
  662. {
  663.     //// FIRST, get the Mac icon value if one exists:
  664.     ODStorageUnit*    su = ODGetSUFromPstObj(ev, part);
  665.     ODIconFamily icons = ODGetIconFamilyProp(ev, su, 
  666.                                 kODPropCustomIcon, kODIconFamily, kAllIconsMask);
  667.     if (icons )
  668.         return icons;
  669.         
  670.     //// OTHERWISE, look for other platform icon values:
  671.     if (ODSUExistsThenFocus(ev,su, kODPropCustomIcon, kODNULL))
  672.     {
  673.         ODULong numValues = su->CountValues(ev);
  674.         for( ODULong i = 1; i <= numValues; i++ )
  675.         {
  676.             su->Focus(ev, kODNULL, kODPosSame, kODNULL, 0, kODPosNextSib);    // Next value
  677.             TempODValueType type = su->GetType(ev);
  678.             if( strncmp(type,kODIconFamilyBaseString,strlen(kODIconFamilyBaseString)) == 0 )
  679.             {
  680.                 // This value is an icon family for some platform. Use the b/w icons
  681.                 // because we don't know what color table the color ones may use.
  682.                 icons = ODGetIconFamilyProp(ev, su, kODPropCustomIcon, type, kBWIconsMask);
  683.                 if( icons )
  684.                     return icons;
  685.             }
  686.         }
  687.         return kODNULL;
  688.     }
  689.     return icons;
  690. }
  691.  
  692.  
  693.  
  694. //--------------------------------------------------------------------
  695. // ODSetPOIconFamily
  696. //--------------------------------------------------------------------
  697.  
  698. void    ODSetPOIconFamily(Environment* ev, ODPart* part, 
  699.             ODIconFamily icons, ODBoolean deleteOtherPlatformIcons)
  700. {
  701.     ODSetIconFamilyProp(ev, ODGetSUFromPstObj(ev, part), 
  702.                                 kODPropCustomIcon, kODIconFamily,
  703.                                 icons, deleteOtherPlatformIcons);
  704. }
  705.  
  706. //--------------------------------------------------------------------
  707. // ODGetIconFamily
  708. //--------------------------------------------------------------------
  709.  
  710. ODIconFamily
  711. ODGetIconFamily(Environment* ev, ODFrame* frame)
  712. {
  713.     TempODPart        part = frame->AcquirePart(ev);
  714.     ODStorageUnit*    su = ODGetSUFromPstObj(ev, (ODPart*)part);
  715.     ODIconFamily    icons = kODNULL;
  716.     
  717.     // FIRST we check for the custom icon resources
  718.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  719.     if (usersFile)
  720.         icons = usersFile->GetCustomIconFamily();
  721.     if (icons)
  722.         return icons;
  723.     
  724.     //// THEN get the property icon value if one exists:
  725.     icons = ODGetPOIconFamily(ev, part);
  726.     if (icons)
  727.         return icons;
  728.  
  729.     //// THEN get the editor's icon from the Mac desktop database:
  730.     ODPlatformType fileType = ODGetIconFilePlatformTypeFromPartSU(ev, su);
  731.     ODPlatformType fileCreator = kODShellSignature;
  732.     
  733.     // Query the desktop database:
  734.     DTPBRec pb;
  735.     pb.ioNamePtr = kODNULL;
  736.     pb.ioVRefNum = -1; //spec.vRefNum;
  737.     THROW_IF_ERROR( PBDTGetPath( &pb ) );        // Sets pb.ioDTRefNum
  738.     
  739.     THROW_IF_ERROR( NewIconSuite(&icons) );
  740.     
  741.     ODBoolean hasIcons = kODFalse;
  742.     TRY{
  743.         char iconBuffer[kLarge8BitIconSize];
  744.         for( pb.ioIconType=1; pb.ioIconType<=6; pb.ioIconType++ ) {
  745.             pb.ioTagInfo = 0;
  746.             pb.ioDTBuffer = (Ptr)&iconBuffer;
  747.             pb.ioDTReqCount = sizeof(iconBuffer);
  748.             pb.ioFileCreator = fileCreator; //info.fdCreator;
  749.             pb.ioFileType = fileType; //info.fdType;
  750.             OSErr err= PBDTGetIconSync(&pb);
  751.             
  752.             if( err == noErr ) {
  753.                 Handle hIcon;
  754.                 WASSERT(pb.ioDTActCount==kIconSize[pb.ioIconType-1]);
  755.                 THROW_IF_ERROR( PtrToHand(iconBuffer,&hIcon, kIconSize[pb.ioIconType-1]) );
  756.                 ASSERT(hIcon!=NULL, kODErrAssertionFailed);
  757.                 ASSERT(*hIcon!=NULL, kODErrAssertionFailed);
  758.                 err= AddIconToSuite(hIcon,icons, kIconType[pb.ioIconType-1] );
  759.                 if( err ) {
  760.                     DisposeHandle(hIcon);
  761.                     THROW_IF_ERROR(err);
  762.                 }
  763.                 hasIcons = kODTrue;
  764.             } else if( err != afpItemNotFound )
  765.                 THROW_IF_ERROR(err);
  766.         }
  767.     
  768.     }CATCH_ALL{
  769.         DisposeIconSuite(icons, kODTrue);
  770.         RERAISE;
  771.     }ENDTRY
  772.     
  773.     // FINALLY use a generic icon:
  774.     if( !hasIcons ) {
  775.         DisposeIconSuite(icons, kODTrue);
  776.  
  777.         short id;
  778.                 if( ODGetIsStationery(ev, frame) )
  779.                     id = genericStationeryIconResource;
  780.                 else
  781.                     id = genericDocumentIconResource;
  782.                 icons= GetGenericIcon(id);
  783.             }
  784.     return icons;
  785. }
  786.  
  787.  
  788. //--------------------------------------------------------------------
  789. // ODSetIconFamily
  790. //--------------------------------------------------------------------
  791.  
  792. void    ODSetIconFamily(Environment* ev, 
  793.                 ODFrame* frame, ODIconFamily icons, ODBoolean deleteOtherPlatformIcons)
  794. {
  795.     TempODPart         part = frame->AcquirePart(ev);
  796.     
  797.     ODSetPOIconFamily(ev, part, icons, deleteOtherPlatformIcons);
  798.     
  799.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  800.     if (usersFile)
  801.         usersFile->SetCustomIconFamily(icons);
  802. }
  803.  
  804. //--------------------------------------------------------------------
  805. // ODGetFileIfRoot
  806. //--------------------------------------------------------------------
  807. PlatformFile*    ODGetFileIfRoot(Environment* ev, ODFrame* frame)
  808. {
  809.     PlatformFile*    usersFile = kODNULL;
  810.     ODBoolean        isRootPartOfDocument;
  811.  
  812.     ASSERT(frame != kODNULL, kODErrIllegalNullInput);
  813.  
  814.     ODFrame*     contFrame = frame->AcquireContainingFrame(ev);
  815.     ODBoolean     isRootPart = (contFrame == kODNULL);
  816.     ODReleaseObject(ev, contFrame);
  817.  
  818.     { TempODWindow window = frame->AcquireWindow(ev);
  819.       isRootPartOfDocument = isRootPart && window->IsRootWindow(ev);
  820.     }
  821.     
  822.     if (isRootPartOfDocument)
  823.     {
  824.         ODDraft* draft;
  825.         { TempODPart part = frame->AcquirePart(ev);
  826.           draft = ODGetSUFromPstObj(ev, part)->GetDraft(ev);
  827.         }
  828.         usersFile = GetPlatformFileFromContainer(ev, 
  829.                                 draft->GetDocument(ev)->GetContainer(ev));
  830.     }
  831.     return usersFile;
  832. }
  833.  
  834.  
  835. //--------------------------------------------------------------------
  836. // DetachIconProc
  837. //--------------------------------------------------------------------
  838.  
  839. static OSErr DetachIconProc( ResType, Handle *theIcon, void */*yourDataPtr*/ )
  840. {
  841.     if( *theIcon ) {
  842.         DetachResource(*theIcon);
  843.         return ResError();
  844.     } else
  845.         return noErr;
  846. }
  847.  
  848. //--------------------------------------------------------------------
  849. // GetGenericIcon
  850. //--------------------------------------------------------------------
  851.  
  852. ODStatic ODIconFamily GetGenericIcon( short iconID )
  853. {
  854.     ODIconFamily icon;
  855.     THROW_IF_ERROR( GetIconSuite( &icon, iconID, svAllAvailableData ) );
  856.     IconActionUPP detachProc = NewIconActionProc(&DetachIconProc);
  857.     (void) ForEachIconDo(icon, svAllAvailableData, detachProc, kODNULL);
  858.     DisposeRoutineDescriptor(detachProc);
  859.     return icon;
  860. }
  861.  
  862.  
  863. //--------------------------------------------------------------------
  864. // ODGetIsStationery
  865. //--------------------------------------------------------------------
  866.  
  867. ODBoolean    ODGetIsStationery(Environment* ev, 
  868.                 ODFrame* frame)
  869. {
  870.     TempODPart        part = frame->AcquirePart(ev);
  871.     ODBoolean        isStationery;
  872.     
  873.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  874.     if (usersFile)
  875.         isStationery = usersFile->IsStationery();
  876.     else
  877.         isStationery = ODGetSUIsStationery(ev, ODGetSUFromPstObj(ev, part));
  878.     return isStationery;
  879. }
  880.  
  881. //--------------------------------------------------------------------
  882. // ODSetIsStationery
  883. //--------------------------------------------------------------------
  884.  
  885. void        ODSetIsStationery(Environment* ev, 
  886.                 ODFrame* frame, ODBoolean isStationery)
  887. {
  888.     { TempODPart part = frame->AcquirePart(ev);
  889.       ODSetBooleanProp( ev, ODGetSUFromPstObj(ev, part),
  890.                             kODPropIsStationery, kODBoolean, isStationery);
  891.     }
  892.     TempPlatformFile usersFile = ODGetFileIfRoot(ev, frame);
  893.     if (usersFile)
  894.         usersFile->SetStationery(isStationery);
  895. }
  896.  
  897. //--------------------------------------------------------------------
  898. // ODSetSUIsStationery
  899. //--------------------------------------------------------------------
  900.  
  901. void        ODSetSUIsStationery(Environment* ev, 
  902.                 ODStorageUnit* su, ODBoolean isStationery)
  903. {
  904.     ODSetBooleanProp( ev, su, kODPropIsStationery, kODBoolean, isStationery);
  905. }
  906.  
  907. //--------------------------------------------------------------------
  908. // ODGetSUIsStationery
  909. //--------------------------------------------------------------------
  910.  
  911. ODBoolean        ODGetSUIsStationery(Environment* ev, 
  912.                 ODStorageUnit* su)
  913. {
  914.     ODBoolean isStationery;
  915.     
  916.     if (su->Exists(ev, kODPropIsStationery, kODBoolean, 0))
  917.         isStationery = ODGetBooleanProp( ev, su, kODPropIsStationery, kODBoolean);
  918.     else
  919.         isStationery = kODFalse;
  920.         
  921.     return isStationery;
  922. }
  923.  
  924. //-------------------------------------------------------------------------------------
  925. // Editor and Kind Menu manipulation functions
  926. //-------------------------------------------------------------------------------------
  927. // copied from LinkDlgs.cpp (with changes by TÇ)
  928. //------------------------------------------------------------------------------
  929. // AddTypesToMenu
  930. //------------------------------------------------------------------------------
  931.  
  932. void AddTypesToMenu(ODTypeList* typeList, MenuHandle kindMenu, ODSession* session)
  933. {
  934.     ODName*                name;
  935.     ODSShort            item = 0;
  936.     Environment*        ev = somGetGlobalEnvironment();
  937.     ODNameSpaceManager*    nsm = session->GetNameSpaceManager(ev);
  938.     
  939.     ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
  940.     
  941.     EditorSet*            editorList = new EditorSet;
  942.     editorList->InitEditorSet();
  943.  
  944.     for (ODType type = typeIter->First(ev);
  945.         typeIter->IsNotComplete(ev);
  946.         type = typeIter->Next(ev))
  947.     {
  948.         if ( GetUserKindFromKind(nsm, type, &name) )
  949.         {
  950.             Str255 itemString;
  951.             IntlToPStr(name, itemString);
  952.             InsertMenuItem(kindMenu, itemString, item++);
  953.             
  954.             ScriptCode itemScript = GetITextScriptCode(name);
  955.             SetPopupItemScript(kindMenu, item, itemScript);
  956.             
  957.             DisposeIText( name );
  958.         }
  959.         else
  960.         {
  961.             // there's no name for this type
  962.             Str255 pKindStr;
  963.             ODTranslation* translation = session->GetTranslation(ev);
  964.             ODPlatformType platformType = 
  965.                 translation->GetPlatformTypeFromISOType(ev, type);
  966.             if ( platformType == kODNULL )
  967.             {
  968.                 // Special menu item
  969.                 CUsingLibraryResources r;
  970.                 GetIndString(pKindStr, kODInfoUtilStrsID, kODStrIndNoKinds); 
  971.             }
  972.             else
  973.             {
  974.                 ODBlockMove(&platformType, &(pKindStr[1]), (ODULong) sizeof(ODPlatformType));
  975.                 pKindStr[0] = (unsigned char) sizeof(ODPlatformType);
  976.             }
  977.             // Allow metacharacters in item text
  978.             InsertMenuItem(kindMenu, "\p ", item++);
  979.             SetMenuItemText(kindMenu, item, pKindStr);
  980.         }
  981.     
  982.         if (!GetAllEditorsForKind(nsm, type, editorList))
  983.             DisableItem(kindMenu, item);
  984.         editorList->RemoveAllEditors();
  985.  
  986.         ODDisposePtr(type);
  987.     }
  988.     ODDeleteObject( editorList );
  989.     ODDeleteObject( typeIter );
  990. }
  991.  
  992. //------------------------------------------------------------------------------
  993. // EnableTypesInMenu
  994. //------------------------------------------------------------------------------
  995.  
  996. ODUShort EnableTypesInMenu(
  997.                     ODTypeList*            typeList,
  998.                     MenuHandle            kindMenu,
  999.                     ODEditor            editor,
  1000.                     ODNameSpaceManager*    nsm)
  1001. {
  1002.     Environment* ev = somGetGlobalEnvironment();
  1003.     ODUShort itemStart = 0;
  1004.  
  1005.     if ( kindMenu && typeList && (typeList->Count(ev) > 0) )
  1006.     {
  1007.         ODTypeListIterator* typeIter = typeList->CreateTypeListIterator(ev);
  1008.         
  1009.         for (ODType type = typeIter->First(ev);
  1010.             typeIter->IsNotComplete(ev);
  1011.             type = typeIter->Next(ev))
  1012.         {
  1013.             if ( editor == kODNULL )
  1014.             {
  1015.                 // Editor is not fixed; Aassume kind can be embedded even if there is
  1016.                 // no editor installed for it
  1017.                 EnableItem(kindMenu, ++itemStart);
  1018.             }
  1019.             else
  1020.             {
  1021.                 if ( EditorSupportsKind(nsm, editor, type) )
  1022.                     EnableItem(kindMenu, ++itemStart);
  1023.                 else
  1024.                     DisableItem(kindMenu, ++itemStart);
  1025.             }
  1026.             ODDisposePtr(type);
  1027.         }
  1028.     
  1029.         ODDeleteObject( typeIter );
  1030.     }
  1031.     
  1032.     return itemStart;
  1033. }
  1034.  
  1035. //------------------------------------------------------------------------------
  1036. // DeleteAllMenuItems
  1037. //------------------------------------------------------------------------------
  1038. ODStatic void DeleteAllMenuItems(MenuHandle theMenu)
  1039. {
  1040.     ODUShort i;
  1041.  
  1042.     for (i = CountMItems(theMenu);  i > 0;  --i)
  1043.     {
  1044.         DeleteMenuItem(theMenu, i);
  1045.     }
  1046. }
  1047.  
  1048. //------------------------------------------------------------------------------
  1049. // SetupEditorMenu
  1050. //------------------------------------------------------------------------------
  1051. ODBoolean SetupEditorMenu(ODType kind,
  1052.                             EditorSet* editorList,
  1053.                             MenuHandle editorMenu, 
  1054.                             ControlHandle popupCtlHndl, 
  1055.                             ODSession* session)
  1056. {
  1057.     ODBoolean anyEditors = (editorList->GetEditorCount() > 0);
  1058.     
  1059.     Environment* ev = somGetGlobalEnvironment();
  1060.     ODNameSpaceManager* nsm = session->GetNameSpaceManager(ev);
  1061.  
  1062.     // And remove all items from the editors menu
  1063.     DeleteAllMenuItems(editorMenu);
  1064.     
  1065.     // Get all editors supporting that kind; Preferred editor must be first
  1066.     if ( kind && !anyEditors)
  1067.     {
  1068.         ODEditor prefEditor = GetSysPrefEditorForKind(nsm, kind);
  1069.         if ( prefEditor )
  1070.             editorList->AddEditor(prefEditor);
  1071.         ODDisposePtr((ODPtr) prefEditor);
  1072.         anyEditors = GetAllEditorsForKind(nsm, kind, editorList);
  1073.     }
  1074.  
  1075.     if ( anyEditors )
  1076.     {
  1077.         AddEditorsToMenu(editorList, editorMenu, session);
  1078.         if ( popupCtlHndl )
  1079.         {
  1080.             SetControlMaximum(popupCtlHndl, editorList->GetEditorCount());
  1081.             HiliteControl(popupCtlHndl, kControlActive);
  1082.         }
  1083.     }
  1084.     else
  1085.     {
  1086.         // The editor popup should be inactive and contain one blank item
  1087.         AppendMenu(editorMenu, "\p");
  1088.         if ( popupCtlHndl )
  1089.         {
  1090.             SetControlMaximum(popupCtlHndl, 1);
  1091.             HiliteControl(popupCtlHndl, kControlInactive);
  1092.         }
  1093.     }
  1094.  
  1095.     if ( popupCtlHndl )
  1096.     {
  1097.         SetControlMinimum(popupCtlHndl, 1);
  1098.         SetControlValue(popupCtlHndl, 1);
  1099.     }
  1100.     
  1101.     return anyEditors;
  1102. }
  1103.  
  1104. //------------------------------------------------------------------------------
  1105. // AddEditorsToMenu
  1106. //------------------------------------------------------------------------------
  1107.  
  1108. void AddEditorsToMenu(EditorSet* editorList,
  1109.                                 MenuHandle editorMenu, 
  1110.                                 ODSession* session)
  1111. {
  1112.     ODName*        name;
  1113.     Str255         pEditorString;
  1114.     ODSShort        item = 0;
  1115.     Environment*         ev = somGetGlobalEnvironment();
  1116.     ODNameSpaceManager*    nsm = session->GetNameSpaceManager(ev);
  1117.     
  1118.     EditorSetIterator* editorIter = editorList->CreateIterator();
  1119.     
  1120.     for (ODType editor = editorIter->First();
  1121.         editorIter->IsNotComplete();
  1122.         editor = editorIter->Next())
  1123.     {
  1124.         if (GetUserEditorFromEditor(nsm, editor, &name))
  1125.         {
  1126.             TempODName tempName = name; // DMc: ensure it's deleted
  1127.             IntlToPStr(name, pEditorString);
  1128.             InsertMenuItem(editorMenu, pEditorString, item);
  1129.             EnableItem(editorMenu, ++item);
  1130.             // comments for SetPopupItemScript say don't call unless the script
  1131.             // needs setting, but there's no way to test that here.  Sounds like
  1132.             // an optimization to me....
  1133.             SetPopupItemScript( editorMenu, item, GetITextScriptCode(name) );
  1134.         }
  1135.         else
  1136.         {
  1137.             // Special menu item in italics
  1138.             CUsingLibraryResources r;
  1139.             GetIndString(pEditorString, kODInfoUtilStrsID, kODStrIndNoEditors); 
  1140.  
  1141.             InsertMenuItem(editorMenu, pEditorString, item);
  1142.             DisableItem(editorMenu, ++item);
  1143.         }
  1144.     }
  1145.  
  1146.     ODDeleteObject( editorIter );
  1147. }
  1148.  
  1149. //------------------------------------------------------------------------------
  1150. // GetThisEditorFromList
  1151. //------------------------------------------------------------------------------
  1152. ODEditor GetThisEditorFromList(ODSShort editorIndex, EditorSet* editorList)
  1153. {
  1154.     ODEditor result = kODNULL;
  1155.     
  1156.     if ( editorIndex > 0 )
  1157.     {
  1158.         ODEditor editor;
  1159.         EditorSetIterator* iter = editorList->CreateIterator();
  1160.         
  1161.         for ( editor = iter->First(); 
  1162.               (--editorIndex > 0) && iter->IsNotComplete(); 
  1163.               editor = iter->Next() )
  1164.         {
  1165.         }
  1166.     
  1167.         delete iter;
  1168.         
  1169.         if ( editor != kODNULL )
  1170.             result = ODISOStrFromCStr((char *) editor);
  1171.     }
  1172.  
  1173.     return result;
  1174. }
  1175.  
  1176. //------------------------------------------------------------------------------
  1177. // IndexOfEditorInList
  1178. //------------------------------------------------------------------------------
  1179. ODSShort IndexOfEditorInList(EditorSet* editorList, ODEditor editor)
  1180. {
  1181.     ODSShort retVal = 0;
  1182.     
  1183.     if ( editorList->GetEditorCount() )
  1184.     {
  1185.         ODSShort i = 1;
  1186.         EditorSetIterator* editorIter = editorList->CreateIterator();
  1187.         
  1188.         for (ODEditor anEditor = editorIter->First();
  1189.             editorIter->IsNotComplete();
  1190.             anEditor = editorIter->Next())
  1191.         {
  1192.             if ( (anEditor == editor) || ODISOStrEqual(anEditor, editor) )
  1193.             {
  1194.                 retVal = i;
  1195.                 break;
  1196.             }
  1197.             i++;
  1198.         }
  1199.  
  1200.         ODDeleteObject( editorIter );
  1201.     }
  1202.     
  1203.     return retVal;
  1204. }
  1205.  
  1206. //------------------------------------------------------------------------------
  1207. // IndexOfKindInList
  1208. //------------------------------------------------------------------------------
  1209. ODSShort IndexOfKindInList(ODTypeList* kindList, ODType kind)
  1210. {
  1211.     ODSShort retVal = 0;
  1212.     
  1213.     Environment* ev = somGetGlobalEnvironment();
  1214.  
  1215.     if ( kindList->Count(ev) )
  1216.     {
  1217.         ODSShort i = 1;
  1218.         ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
  1219.         
  1220.         TRY
  1221.         
  1222.             for (ODType type = kindIter->First(ev);
  1223.                 kindIter->IsNotComplete(ev);
  1224.                 type = kindIter->Next(ev), i++)
  1225.             {
  1226.                 if ( ODISOStrEqual(type, kind) )
  1227.                     retVal = i;
  1228.                 ODDisposePtr(type);
  1229.                 if ( retVal != 0 )
  1230.                     break;
  1231.             }
  1232.  
  1233.         CATCH_ALL
  1234.             ODDeleteObject(kindIter);
  1235.             RERAISE;
  1236.         ENDTRY
  1237.         
  1238.         ODDeleteObject(kindIter);
  1239.     }
  1240.     
  1241.     return retVal;
  1242. }
  1243.  
  1244. //------------------------------------------------------------------------------
  1245. // GetThisKindFromList
  1246. //------------------------------------------------------------------------------
  1247. ODType GetThisKindFromList(ODSShort kindItem, ODTypeList* kindList)
  1248. {
  1249.     Environment* ev = somGetGlobalEnvironment();
  1250.     ODType type = kODNULL;
  1251.     ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
  1252.  
  1253.     for ( type = kindIter->First(ev); 
  1254.           (--kindItem > 0) && kindIter->IsNotComplete(ev); 
  1255.           type = kindIter->Next(ev) )
  1256.     {
  1257.         ODDisposePtr(type);
  1258.         type = kODNULL;
  1259.     }
  1260.  
  1261.     ODDeleteObject(kindIter);
  1262.  
  1263.     return type;
  1264. }
  1265.  
  1266.  
  1267. //------------------------------------------------------------------------------
  1268. // ContentValueTypes
  1269. //------------------------------------------------------------------------------
  1270. void ContentValueTypes(ODStorageUnit* contentSU, ODTypeList* typeList)
  1271. {
  1272.     TempODType hfsType = kODNULL;
  1273.  
  1274.     TRY
  1275.         ODULong        count;
  1276.         ODULong        index;
  1277.         
  1278.         Environment* ev = somGetGlobalEnvironment();
  1279.  
  1280.         ODTranslation* translation = contentSU->GetSession(ev)->GetTranslation(ev);
  1281.         hfsType = translation->GetISOTypeFromPlatformType(ev, kODFileType_hfs, kODPlatformDataType);
  1282.  
  1283.         contentSU->Focus(ev, kODPropContents, kODPosUndefined, 0, 0, kODPosUndefined);
  1284.         count = contentSU->CountValues(ev);
  1285.         for (index = 1; index <= count; ++index)
  1286.         {
  1287.             contentSU->Focus(ev, kODPropContents, kODPosUndefined, 0, index, kODPosUndefined);
  1288.             TempODType type = contentSU->GetType(ev);
  1289.             if ( !ODISOStrEqual(type, hfsType) )
  1290.                 typeList->AddLast(ev, type);
  1291.         }
  1292.     CATCH_ALL
  1293.     ENDTRY
  1294. }
  1295.  
  1296. //------------------------------------------------------------------------------
  1297. // ODUserRenameFile
  1298. //------------------------------------------------------------------------------
  1299.  
  1300.  
  1301. ODStatic ODBoolean ODUserRenameFile(Environment* ev,
  1302.                     ODSession* session, 
  1303.                     PlatformFile*    usersFile, 
  1304.                     ODIText* name,
  1305.                     DescType replaceOption)
  1306. {
  1307.     ODBoolean    fileRenamed = kODFalse;
  1308.     
  1309.     // name to aStr255
  1310.     Str255 aStr255;
  1311.     
  1312.     GetITextPString(name, aStr255);
  1313.  
  1314.     TRY
  1315.         usersFile->Rename(aStr255);
  1316.         fileRenamed = kODTrue;
  1317.     CATCH_ALL
  1318.         if (ErrorCode() == dupFNErr)
  1319.         {
  1320.             switch (replaceOption) {
  1321.             case kAEAsk:
  1322.                 ParamText(aStr255, "\p","\p","\p");
  1323.                 fileRenamed = ODAskUserReplace(ev, session);
  1324.                 break;
  1325.             case kAEYes:
  1326.                 fileRenamed = kODTrue; break;
  1327.             case kAENo:
  1328.                 fileRenamed = kODFalse; break;
  1329.             }
  1330.             
  1331.             if (fileRenamed)
  1332.             {
  1333.                 ODFileSpec fsspec = usersFile->GetFileSpec();
  1334.                 ODError result = HDelete(fsspec.vRefNum,fsspec.parID,aStr255);
  1335.                 if ( result!=wPrErr && result!=fLckdErr && 
  1336.                                     result!=fBsyErr && result!=afpAccessDenied )
  1337.                 {
  1338.                     TRY
  1339.                         usersFile->Rename(aStr255);
  1340.                     CATCH_ALL
  1341.                         WARN("File renaming failed, err %ld",ErrorCode());
  1342.                         fileRenamed = kODFalse;
  1343.                     ENDTRY
  1344.                 }
  1345.                 else
  1346.                 {
  1347.                     fileRenamed = kODFalse;
  1348.                     if (replaceOption == kAEAsk)
  1349.                         switch(result)
  1350.                         {
  1351.                             case wPrErr:
  1352.                             case fLckdErr:
  1353.                             case fBsyErr:
  1354.                             {
  1355.                                 CUsingLibraryResources res;
  1356.                                 StopAlert(kFilelockedAlrtID, GetODDialogFilter());
  1357.                                 break;
  1358.                             }
  1359.                             default:
  1360.                                 SysBeep(2);
  1361.                         }
  1362.                     else
  1363.                         SysBeep(2);
  1364.                 }
  1365.             }
  1366.         }
  1367.         else 
  1368.             RERAISE;
  1369.     ENDTRY
  1370.     return( fileRenamed );
  1371. }
  1372.  
  1373. //------------------------------------------------------------------------------
  1374. // ODAskUserReplace
  1375. //------------------------------------------------------------------------------
  1376.  
  1377. ODBoolean    ODAskUserReplace(Environment* ev,
  1378.                             ODSession* session)
  1379. // Pass in the name in question via ParamText(^0).
  1380. {  
  1381.     CUsingLibraryResources r;
  1382.     ODBoolean    doReplace    = kODFalse;
  1383.     short          itemHit     = 0;
  1384.     DialogPtr     dlg         = ODGetNewDialog(ev, kNameConflictDlgID, 
  1385.                                     session, kODFalse );
  1386.     if (dlg)
  1387.     {
  1388.         Handle        scratchHandle = kODNULL;
  1389.         Rect        scratchRect;
  1390.  
  1391.         SetPort(dlg);
  1392.         
  1393.             // Set the draw routine for the default button outline item
  1394.         GetDialogItem(dlg, kNameConflictDefaultButtonItem, &itemHit, &scratchHandle, &scratchRect);
  1395.         SetDialogItem(dlg, kNameConflictDefaultButtonItem, itemHit, 
  1396.                  (Handle)GetODOutlineDefaultButtonDrawProc(), &scratchRect);
  1397.                 
  1398.         ShowWindow(dlg);
  1399.  
  1400.         do {
  1401.             ModalDialog(GetODDialogFilter(), &itemHit);
  1402.             switch(itemHit)
  1403.             {
  1404.                 case kNameConflictReplaceBtn:
  1405.                     doReplace = kODTrue;
  1406.                     break;
  1407.                 case kNameConflictCancelBtn:
  1408.                     break;
  1409.             }
  1410.         } while ((itemHit != kNameConflictReplaceBtn) && 
  1411.                                         (itemHit != kNameConflictCancelBtn));
  1412.                 
  1413.         ODDisposeDialog(dlg);
  1414.     }
  1415.     return doReplace;
  1416. }
  1417.  
  1418. //------------------------------------------------------------------------------
  1419. //    CommentsDontMatch
  1420. //
  1421. //    This compares 2 ODIText strings to see if they match and returns TRUE if
  1422. //    they do not match.  It take into account the fact that the comments field
  1423. //    of the desktop database clips its string to 200 characters.
  1424. //
  1425. //    Returns false if the strings are identical but the script/language are
  1426. //    not.  This is because these values in dtComments have been set using
  1427. //    system defaults while those in propComments were actually saved, and
  1428. //    should therefore take precedence. <eeh>
  1429. //
  1430. //    propComments can be NULL, dtComments cannot
  1431. //------------------------------------------------------------------------------
  1432.  
  1433. ODBoolean
  1434. CommentsDontMatch(ODIText* dtComments, ODIText* propComments)
  1435. {
  1436.     ODBoolean    result;
  1437.     ODULong        dtLen, propLen;
  1438.     Str255        dtStr, propStr;
  1439.     
  1440.     if (dtComments != kODNULL)
  1441.         dtLen = GetITextStringLength(dtComments);
  1442.     else
  1443.         dtLen = 0;
  1444.     if (propComments == kODNULL)
  1445.         return (dtLen != 0);
  1446.     propLen = GetITextStringLength(propComments);
  1447.     if (dtLen == 0)
  1448.         return (propLen != 0);
  1449.     
  1450.     // if either string is length 0 (or NULL) we won't get here
  1451.     WASSERT(dtComments && propComments);
  1452.     result = kODTrue;
  1453.  
  1454.     // because the Finder does not store script and language with the
  1455.     // comments or file names, we ignore these in comparing strings.  That
  1456.     // is, if the strings are identical byte-for-byte, we consider them
  1457.     // to be equal.  That way, the string *we* stored will be used, as will
  1458.     // the script and language information we stored with it.
  1459.  
  1460.     ODBoolean lengthsMatch =
  1461.             (dtLen == propLen) || (dtLen == 200 && propLen >= 200);
  1462.     if ( lengthsMatch )
  1463.     {
  1464.         GetITextPString(dtComments, (StringPtr) &dtStr);
  1465.         GetITextPString(propComments, (StringPtr) &propStr);
  1466.         propStr[0] = dtStr[0];            // fix the 200 case
  1467.         result = !EqualString( dtStr, propStr, kODTrue, kODTrue );
  1468.     }
  1469.     return result;
  1470.  
  1471. }
  1472.  
  1473.  
  1474. void SetAllWindowShowLinks(Environment* ev, ODWindowState* winState, ODBoolean showLinks)
  1475. {
  1476.     ODWindowIterator* iter = kODNULL; ODVolatile(iter);
  1477.             
  1478.     TRY
  1479.  
  1480.         iter = winState->CreateWindowIterator(ev);
  1481.     
  1482.         for (ODWindow* window = iter->First(ev); iter->IsNotComplete(ev);
  1483.                 window = iter->Next(ev))
  1484.         {
  1485.             if (window)
  1486.             {
  1487.                 window->SetShouldShowLinks(ev, showLinks);
  1488.                 ODFrame* root = window->GetRootFrame(ev);
  1489.                 root->Invalidate(ev, kODNULL, kODNULL);
  1490.             }
  1491.         }
  1492.         ODDeleteObject(iter);
  1493.  
  1494.     
  1495.     CATCH_ALL
  1496.  
  1497.         ODDeleteObject(iter);
  1498.         RERAISE;
  1499.  
  1500.     ENDTRY
  1501. }
  1502.  
  1503. //------------------------------------------------------------------------------
  1504. // TranslateValueTypes
  1505. //------------------------------------------------------------------------------
  1506. void TranslateValueTypes(
  1507.                 ODTypeList*    kindList,
  1508.                 ODTypeList*    translateToList,
  1509.                 OrderedCollection* translateFromList,
  1510.                 ODSession*    session)
  1511. {
  1512.     Environment* ev = somGetGlobalEnvironment();
  1513.  
  1514.     ODTranslation* translation = session->GetTranslation(ev);
  1515.  
  1516.     ODTypeListIterator* kindIter = kindList->CreateTypeListIterator(ev);
  1517.     
  1518.     ODUShort kindIndex = 0;
  1519.  
  1520.     for (ODType kind = kindIter->First(ev);
  1521.         kindIter->IsNotComplete(ev);
  1522.         kind = kindIter->Next(ev))
  1523.     {
  1524.         ++kindIndex;
  1525.  
  1526.         TRY
  1527.             ODTypeList* toList = translation->GetTranslationOf(ev, kind);
  1528.             
  1529.             ODTypeListIterator* toIter = toList->CreateTypeListIterator(ev);
  1530.             
  1531.             for (ODType toKind = toIter->First(ev);
  1532.                 toIter->IsNotComplete(ev);
  1533.                 toKind = toIter->Next(ev))
  1534.             {
  1535.                 TRY
  1536.                 
  1537.                     if ( (kindList->Contains(ev, toKind) == kODFalse)
  1538.                         &&
  1539.                          (translateToList->Contains(ev, toKind) == kODFalse)
  1540.                        )
  1541.                     {
  1542.                         translateToList->AddLast(ev, toKind);
  1543.                         translateFromList->AddLast((void*) kindIndex);
  1544.                     }
  1545.                 
  1546.                 CATCH_ALL
  1547.                 ENDTRY
  1548.                 ODDisposePtr(toKind);
  1549.             }
  1550.             delete toIter;
  1551.             delete toList;
  1552.  
  1553.         CATCH_ALL
  1554.         ENDTRY
  1555.  
  1556.         ODDisposePtr(kind);
  1557.     }
  1558.     delete kindIter;
  1559. }
  1560.  
  1561. //------------------------------------------------------------------------------
  1562. // StringPtrFromStrHandle
  1563. //------------------------------------------------------------------------------
  1564.  
  1565. ODStatic StringPtr StringPtrFromStrHandle(StringHandle strHandle)
  1566. {
  1567.     StringPtr result = kODNULL;
  1568.  
  1569.     if ( strHandle )
  1570.     {
  1571.         ODULong size = GetHandleSize((Handle) strHandle);
  1572.         StringPtr strPtr = (StringPtr) ODLockHandle((ODHandle) strHandle);
  1573.         result = (StringPtr) ODNewPtr(size);
  1574.         ODBlockMove(strPtr, result, size);
  1575.         ODUnlockHandle((ODHandle) strHandle);
  1576.     }
  1577.  
  1578.     return result;
  1579. }
  1580.  
  1581. //------------------------------------------------------------------------------
  1582. // DefaultMenuStringForKind
  1583. //------------------------------------------------------------------------------
  1584.  
  1585. ODStatic StringPtr DefaultMenuStringForKind()
  1586. {
  1587.     CUsingLibraryResources r;
  1588.  
  1589.     StringPtr result = kODNULL;
  1590.  
  1591.     StringHandle strHandle = GetString(kODPartInfoStrUnknownID);
  1592.     if ( strHandle )
  1593.     {
  1594.         result = StringPtrFromStrHandle(strHandle);
  1595.         ReleaseResource((Handle) strHandle);
  1596.     }
  1597.     else
  1598.     {
  1599.         strHandle = NewString("\p");
  1600.         result = StringPtrFromStrHandle(strHandle);
  1601.         ODDisposeHandle((ODHandle) strHandle);
  1602.     }
  1603.     return result;
  1604. }
  1605.  
  1606. //------------------------------------------------------------------------------
  1607. // GetMenuStringForKind
  1608. //------------------------------------------------------------------------------
  1609.  
  1610. ODStatic void GetMenuStringForKind(
  1611.     ODSession*        session,
  1612.     ODType            kind,
  1613.     StringPtr*        itemString,
  1614.     ODScriptCode*    itemScript)
  1615. {
  1616.     ODName*                name;
  1617.     Environment*        ev = somGetGlobalEnvironment();
  1618.     ODNameSpaceManager*    nsm = session->GetNameSpaceManager(ev);
  1619.  
  1620.     if ( GetUserKindFromKind(nsm, kind, &name) )
  1621.     {
  1622.         TempODName tempName = name; // DMc: ensure it's deleted
  1623.         *itemString = (StringPtr) ODNewPtr(GetITextStringLength(name)+1);
  1624.         IntlToPStr(name, *itemString);
  1625.         *itemScript = GetITextScriptCode(name);
  1626.     }
  1627.     else
  1628.     {
  1629.         // No available editors support this kind
  1630.         ODTranslation* translation = session->GetTranslation(ev);
  1631.         ODPlatformType platformType = translation->GetPlatformTypeFromISOType(ev, kind);
  1632.         if ( platformType != kODNULL )
  1633.         {
  1634.             *itemString = (StringPtr) ODNewPtr(sizeof(ODPlatformType) + 1);
  1635.             ODBlockMove(&platformType, &((*itemString)[1]), (ODULong) sizeof(ODPlatformType));
  1636.             (*itemString)[0] = (unsigned char) sizeof(ODPlatformType);
  1637.         }
  1638.         else
  1639.         {
  1640.             *itemString = DefaultMenuStringForKind();
  1641.         }
  1642.         *itemScript = smSystemScript;
  1643.     }
  1644. }
  1645.  
  1646. //------------------------------------------------------------------------------
  1647. // AddTranslationKindToMenu
  1648. //------------------------------------------------------------------------------
  1649.  
  1650. void AddTranslationKindToMenu(
  1651.         ODType        kind, 
  1652.         MenuHandle    kindMenu,
  1653.         short        item,
  1654.         ODBoolean    insert,
  1655.         ODSession*    session)
  1656. {
  1657.     StringPtr itemString;
  1658.     ODScriptCode itemScript;
  1659.     
  1660.     GetMenuStringForKind(session, kind, &itemString, &itemScript);
  1661.     TempODString tempItemString = (char*) itemString; // DMc: ensure it's deleted
  1662.  
  1663.     if ( insert )
  1664.     {
  1665.         InsertMenuItem(kindMenu, itemString, item);
  1666.         item += 1;
  1667.     }
  1668.     else
  1669.         SetMenuItemText(kindMenu, item, itemString);
  1670.     
  1671.     SetPopupItemScript(kindMenu, item, itemScript);
  1672. }
  1673.